package com.gae.helloUS;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

@SuppressWarnings("serial")
public class HelloUSServlet extends HttpServlet {
	
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		resp.setContentType("text/plain");
		resp.getWriter().println("Hello, world, sohow");
		resp.getWriter().println("\n\nWhats up");
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
		    throws ServletException, IOException {
		       //response handling
				PrintWriter out = response.getWriter();
		       response.setContentType("text/html");
		       //response.getWriter().println("Hello, world, sohow2do the Post");
		       out.println("<a href=\"index.html\">");
		       String[] IDs = {"software","engineer"};
		       String[] passwords = {"123456","7890"};
		       String ID = request.getParameter("ID");
		       String password = request.getParameter("password");
		       int i=0;
		       
		       for(i=0; i<2; i++)
		       {
		    	   if(ID.equals(IDs[i])&& password.equals(passwords[i]))
		    	   {   response.getWriter().println("Hello, world!");
		    	       break;
		    	   }
		    	   //else
		    	   //{
		    		 //  
		    	   //}
		       }
		       
		       if(i==2)
		    	   response.sendRedirect("/index.html");
	}
		       
}
